/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controler;

import graph.Edge;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import view.EdgeItem;
import view.NodeItem;

/**
 *
 * @author borysfan
 */
public class EdgeItemControler {
    private NodeItemControler nodeItemControler;
    private EdgeItem edgeItem;
    private Edge edge;
    private Controler controler;
    private NodeItemControler nodeBegin;
    private NodeItemControler nodeEnd;


    public EdgeItemControler(Controler c){
        controler = c;
        edgeItem = new EdgeItem(this);
        edge = new Edge();
        initActions();
    }

    public void setEdge(Edge e){
        edge=e;
    }

    public void initActions(){
        edgeItem.addMouseListener(new MouseListener(){
            public void mouseClicked(MouseEvent e) {
               controler.getToolboxControler().redEdge();
               System.out.println("Teraz jak przeciagniesz od wierzcholka do wierzcholka to zrobi sie polaczenie");
               controler.setConnectActions();
            }
            public void mousePressed(MouseEvent e) {
                /*JComponent c = (JComponent) e.getSource();
                TransferHandler handler = c.getTransferHandler();
                handler.exportAsDrag(c, e, TransferHandler.COPY);*/

            }

            public void mouseReleased(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
        });
    }
    /////////////GETTERY I SETTERY
    public EdgeItem getView(){
        return edgeItem;
    }

    public Edge getModel(){
        return edge;
    }

    public void setBeginNode(NodeItemControler nic) {
        nodeBegin = nic;
        edgeItem.setBeginNode(nic.getView());
    }

    public void setEndNode(NodeItemControler nic) {
        nodeEnd = nic;
        edgeItem.setEndNode(nic.getView());
         controler.getToolboxControler().blackEdge();
        
    }

    public NodeItemControler getBeginNode(){
        return nodeBegin;
    }

    public NodeItemControler getEndNode(){
        return nodeEnd;
    }

    public void showProperties() {
        controler.showEdgeProperties(this);
    }

    public void saveName(String s){
        this.edge.setName(s);
    }

    public void refresh() {
        controler.getMainPanel().getView().updateUI();
    }

    public  void saveVMax(String edgeVMax) {
        this.edge.setVMax(Double.parseDouble(edgeVMax));
    }

    public  void saveLength(String edgeLength) {
        this.edge.setLength(Double.parseDouble(edgeLength));
    }

    public void saveNotes(String edgeNotes) {
        this.edge.setNotes(edgeNotes);
    }


    public void saveLock(boolean edgeLock) {
        this.edge.setLock(edgeLock);
    }

    public void saveWeather(int weather) {
        this.edge.setWeatherConditions(weather);
    }

    public void saveRoad(int road) {
        this.edge.setRoadConditions(road);
    }

    public void saveTraffic(int traffic) {
        this.edge.setTraffic(traffic);
    }

    public void saveWeatherSlider(int weatherslider) {
        this.edge.setWeatherSlider(weatherslider);
    }

    public void saveRoadSlider(int roadSlider) {
        this.edge.setRoadSlider(roadSlider);
    }

  

    
    ////////////ACTIONS



}
